/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.to.aboomy.bannersample.pagetransformer;

import com.bumptech.glide.util.LogUtil;
import com.to.aboomy.banner.BannerViewPager;
import ohos.agp.components.Component;

import static com.to.aboomy.banner.BannerViewPager.PageType.PREVIOUS;

/**
 * AccordionTransformer
 *
 * @since 2021-08-04
 */
public class AccordionTransformer implements BannerViewPager.PageTransformer {
    private static final String ACCORDIONTRANSFORMER = "AccordionTransformer";

    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {
        switch (pageType) {
            case PREVIOUS:
                page.setScaleX(1F);

                break;
            case CURRENT:
                if (offsetPixels > 0) {
                    page.setPivotX(page.getWidth());
                    page.setScaleX(1.0f - offset);
                    LogUtil.error(ACCORDIONTRANSFORMER, "CURRENT左滑");
                } else {
                    page.setPivotX(0f);
                    page.setScaleX(1 - offset);
                    LogUtil.error(ACCORDIONTRANSFORMER, "CURRENT右滑");
                }
                break;
            case NEXT:
                if (offsetPixels > 0) {
                    page.setPivotX(0);
                    page.setScaleX(offset);
                    LogUtil.error(ACCORDIONTRANSFORMER, "NEXT左滑");
                } else {
                    page.setPivotX(page.getWidth());
                    page.setScaleX(offset);
                    LogUtil.error(ACCORDIONTRANSFORMER, "NEXT左滑");
                }
                break;
            case OTHER:
                page.setScaleX(1F);
                break;
            default:
                break;
        }
    }
}
